<?php
	session_start();
	error_reporting (E_ALL ^ E_NOTICE);
	echo "<h2>My Itinerary</h2>";
	$username = $_SESSION['user'];
	$hostname_conn = "127.0.0.1"; 
	$database_conn = "onestoptravelsgdb";
	$username_conn = "admin"; 
	$password_conn = "1stoptravel";
	$db_handle = mysql_connect($hostname_conn, $username_conn, $password_conn);
	if (!db_handle) {
		die("Database connection error");
	} else {
		$db_found = mysql_select_db($database_conn, $db_handle);
		if ($db_found) {
			$SQL = "SELECT * FROM tmp_itinerary WHERE username = '" . $username ."'";
			$result = mysql_query($SQL);
			if (mysql_num_rows($result) == 0) {
				echo "No items added to itinerary yet.";
			}
			else {
				while ($res = mysql_fetch_array($result)) {
					echo "<div class=\"accordion\" id=\"itineraryaccordion\">";
						echo "<div class=\"accordion-group\">";
						$SQL = "SELECT * FROM accommodations WHERE id = " . $res['accommid'];
						$result = mysql_query($SQL);
						while($row = mysql_fetch_array($result)) {
							echo "<div class=\"accordion-heading\">";
								echo "<a class=\"accordion-toggle\" data-toggle=\"collapse\" data-parent=\"#itineraryaccordion\" href=\"#" . $row['name'] . "collapse\">";
								echo $row['name'];
								echo "</a>";
							echo "</div>";
							echo "<div id=\"" . $row['name'] . "collapse\" class=\"accordion-body collapse in\">";
								echo "<div class=\"accordion-inner\">";
								echo "Description: " . $row['description'] . "<br/>" .
									"Address: " . $row['address'] . "<br/>" .
									"Cost: " . $row['mincost'] . " - " . $row['maxcost'] . " (" . $row['currency'] . ")" . "<br/>" .
									"Country: " . $row['country'] . "<br/>" .
									"Area: " . $row['area'] . "<br/>" .
									"Pax: " . $row['minpax'] . " - " . $row['maxpax'] . "<br/>" .
									"Website: " . ($row['url'] == "" ? "NA" : $row['url']) . "<br/>" .
									"Email: " . ($row['email'] == "" ? "NA" : $row['email']) . "<br/>" .
									"Phone: " . ($row['phone'] == "" ? "NA" : $row['phone']) . "<br/>" .
									"Rating: " . $row['rating'] . "<br/><br/>" .
									"<a class=\"btn\" target=\"_blank\" href=\"" . $row['booking'] . "\">Book now</a><br/>";
								echo "</div>";
							echo "</div>";
						}
						echo "</div>";
					echo "</div>";
				}
			}
		}
		else {
			die("Database not found error");
		}
	}
	mysql_close($db_handle);
	/*if (isset($_SESSION['login']) && $_SESSION['login'] == "1")
		
	else {
		echo "<h1>You do not have permission to view this page.</h1><br/>";
		echo "<p><a href=\"#login\" class=\"btn btn-primary\" data-toggle=\"modal\">Login here</a></p>";
	}*/
?>